package sanrenxing.dayEnd.backRepertoryTotal.dao;


import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import sanrenxing.dayEnd.backRepertoryTotal.domain.BalanceSheet;

import java.util.List;

/**
 * 功能:
 * 编写者：
 * 日期：2021
 * 版本：1.0
 */
public interface BalanceSheetDao {
    /**
     * 根据证券名称删除一行
     *
     * @param seName
     * @return
     */
    @Delete("delete from balanceSheet where seName=#{seName}")
    public int delete(@Param("seName") String seName);

    /**
     * 分页查询条件
     *
     * @param start
     * @param rows
     * @param condition
     * @return
     */
    @Select("select sec.seName,(select sum(sumMoney) from secRecAndPayStock where businStat=-1) outflow,(select sum(sumMoney) from secRecAndPayStock where businStat=1) inflow,\n" +
            "(s.price*s.tranMoney*t.commRate) commRate,(s.price*s.tranMoney*e.handFee) handFee,(s.price*s.tranMoney*e.staDuty) staDuty,(s.price*s.tranMoney*e.tranFee) tranFee,(s.price*s.tranMoney*e.collFee) collFee,s.settMoney as amos,\n" +
            "tranDate from securitiesTradingData s join exchangeVarietyRate e on s.BreedRateId=e.BreedRateId join financialsecurities sec on s.seId=sec.seId \n" +
            "join tradingSeat t on s.stockId=t.stockId where s.tranStatus=1")

    public List<BalanceSheet> findByPage(@Param("start") int start, @Param("rows") int rows, @Param("condition") String condition);

    /**
     * 按条件统计记录数
     *
     * @param condition 统计条件
     * @return 条件
     */
    @Select("select count(*) from securitiesTradingData s join exchangeVarietyRate e on s.BreedRateId=e.BreedRateId join financialsecurities sec on s.seId=sec.seId \n" +
            "join tradingSeat t on s.stockId=t.stockId where s.tranStatus=1 and 1=1 ${condition}")
    public int count(@Param("condition") String condition);
}
